<?php


namespace app\common\service;


use app\common\tools\AliyunSms;

class SmsService
{
    /**
     * 发送登录/注册验证
     * @param $phone
     * @throws ApiException
     * @throws
     * @author 刘宏盟
     */
    public function smsCode($phone)
    {
        $key = 'login.sms.code.';
        $code = mt_rand(10000, 99999);
        [$res, $msg] = AliyunSms::instance()->sendLogin($phone, $code);
        if (!$res) {
            return json($msg);
        }
        // 记录缓存,
        cache($key . $phone, ['code' => $code, 'error' => 0], 300);
        //LoginSmsCode::instance()->set($key . $phone, ['code' => $code, 'error' => 0], 5 * 60);
    }
}
